﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using SGRapidForm.Common;
using System.Web.SessionState;

namespace SGDemo.Web
{
    /// <summary>
    /// 调用OA说明
    /// </summary>
    public class OAHandler : IHttpHandler, IRequiresSessionState 
    {
        public const string ContextKey = "SGRapidForm.Common.ApplicationContext";

        public void ProcessRequest(HttpContext context)
        {
            if(HttpContext.Current.Session[ContextKey] == null){
                throw new ArgumentNullException("Session中无当前登录用户信息");
            }

            string ccflowUrl = ConfigurationManager.AppSettings["ConnectCCFlow"];
            string userName = ApplicationContext.Current.UserName;
            string sid = ApplicationContext.Current.SessionID;

            switch (context.Request.RawUrl)
            {
                case "/Handler/OAHandler.ashx?Action=Start": context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}", ccflowUrl, userName, "StartSmall", sid), true); break;
                case "/Handler/OAHandler.ashx?Action=Work": context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}", ccflowUrl, userName, "EmpWorksSmall", sid), true); break;
                case "/Handler/OAHandler.ashx?Action=Run": context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}", ccflowUrl, userName, "RuningSmall", sid), true); break;
                case "/Handler/OAHandler.ashx?Action=Doned": context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}", ccflowUrl, userName, "FlowSearchSmall", sid), true); break;
                case "/Handler/OAHandler.ashx?Action=Search": context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}", ccflowUrl, userName, "CalendarSmall", sid), true); break;
                case "/Handler/OAHandler.ashx?Action=Manage": context.Response.Redirect("http://110.80.17.26:8052/ccflow/WF/Admin/XAP/Designer.aspx"); break;

            }
            //待办明细
            if (context.Request.QueryString["Action"] == "DaiBanItem")
            {
                context.Response.Redirect(string.Format("{0}Jump.aspx?id={1}&url={2}&SID={3}&FK_Flow={4}&FK_Node={5}&FID={6}&WorkID={7}", ccflowUrl, userName, "jump", sid, context.Request.QueryString["FK_Flow"], context.Request.QueryString["FK_Node"], context.Request.QueryString["FID"], context.Request.QueryString["WorkID"]), true);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}